﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using Plumber.Masters.ModuleData;

namespace Plumber.Accounting.Forms
{
    public partial class CreateLiquidationTaxPayment : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        private DRMasterType dRMasterType;

        public double AmountTotal { set { ntbTotal.Double = value; } }

        public double AmountToPayed { set { ntbTotalPay.Double = value; } get { return ntbTotalPay.Double; } }

        public string BankCash { get { return cbbFromType.GetValue<string>(); } }

        public string BankCashCode { get { return rdrFromCode.Text; } }

        public DateTime JEDate { set { ctbDate.Today = value; } get { return ctbDate.Today; } }

        public CreateLiquidationTaxPayment()
        {
            InitializeComponent();
            InitializeAuxComponent();
        }

        private void InitializeAuxComponent()
        {
            dRMasterType = new DRMasterType(DRMasterType.Module.All);

            rdrFromCode.RadarForm = new RadarMasterForm(RadarMasterForm.Module.All);
            rdrFromCode.RadarForm.EnableAddOnFly = false;
            rdrFromCode.DescriptionControl = lblDescFrom;

            cbbFromType.AttachDataReader(new RRMasterTypeByType(MasterTypes.E_BankCash));
            cbbFromType_SelectedValueChanged(this, EventArgs.Empty);

            ntbTotal.Prefix = Properties.Resources.CurrencySimbol;
            ntbTotalPay.Prefix = Properties.Resources.CurrencySimbol;
        }

        private void cbbFromType_SelectedValueChanged(object sender, EventArgs e)
        {
            dRMasterType.Find(cbbFromType.GetValue<string>());
            rdrFromCode.Enabled = dRMasterType.GetValue<CodeMode>(PL_MasterType.CodeMode) != CodeMode.E_IsEmpty;
            if (!rdrFromCode.Enabled)
                rdrFromCode.Text = string.Empty;
            else
            {
                rdrFromCode.AttachCodeType(cbbFromType.GetValue<string>());
                rdrFromCode.RadarForm.FilterType = cbbFromType.GetValue<string>();
            }
            lblDescFrom.Text = string.Empty;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}